package com.demo;

import java.util.Scanner;

public class StringDemo4 {
    public static void main(String[] args) {
        //1.定义两个变量记录正确的用户名和密码
        String name="zhangsan";
        String password="123456";

        Scanner scanner = new Scanner(System.in);
        for(int i=0;i<3;i++) {
            //2.键盘录入用户名和密码
            System.out.println("请输入用户名:");
            String username = scanner.next();
            System.out.println("请输入密码:");
            String userpassword = scanner.next();

            //3.比较
            if (username.equals(name) && userpassword.equals(password)) {
                System.out.println("用户登录成功！");
                break;
            } else {
                if(i==2){
                    System.out.println("账户"+name+"被锁定，请联系管理员！");
                }else {
                    System.out.println("用户名或密码有误！！你还剩下" + (2 - i) + "次机会。");
                }
            }
        }
    }
}
